package net.sunofbeach.blog.dao;

import net.sunofbeach.blog.pojo.NavigationCategory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface NavigationCategoryDao extends JpaRepository<NavigationCategory, String>, JpaSpecificationExecutor<NavigationCategory> {


    NavigationCategory findOneById(String id);

    @Modifying
    int deleteAllById(String navigationCateryId);


    @Modifying
    @Query(nativeQuery = true,value = "UPDATE `tb_navigation_categories` SET `status` = 0 WHERE `id` = ?")
    int deleteNavigationCategoryByUpdateState(String navigationCategoryId);


    //@Query(nativeQuery = true,value = "select * from `tb_navigation_categories`  WHERE `status` = ? order by `create_time` DESC")
    @Query(nativeQuery = true,value = "select * from `tb_navigation_categories`  WHERE `status` = ? order by `order` ASC")
    List<NavigationCategory> listNavigationCategoriesByState(String status);
}
